package com.example.gobang.game;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class OnlineUserManager {
    // 表示用户在游戏大厅的在线状态
    private final ConcurrentHashMap<Integer, WebSocketSession> gameLobby = new ConcurrentHashMap<>();
    // 表示用户在游戏房间的在线状态
    private final ConcurrentHashMap<Integer, WebSocketSession> gameRoom = new ConcurrentHashMap<>();
    public void enterGameLobby(int userId, WebSocketSession session){
        gameLobby.put(userId, session);
    }

    public void exitGameLobby(int userId){
        gameLobby.remove(userId);
    }

    public WebSocketSession getOnline(int userId){
        return gameLobby.get(userId);
    }

    public void enterGameRoom(int userId, WebSocketSession session){
        gameRoom.put(userId, session);
    }

    public void exitGameRoom(int userId){
        gameRoom.remove(userId);
    }

    public WebSocketSession getOnlineRoom(int userId){
        return gameRoom.get(userId);
    }
}
